$(function() {

  // 点击错误提示款隐藏
  $(".error-closing").click(function(){
    $(".error-prompt").css("display","none");
  });

  // 错误提示款隐藏
  $("#content").focus(function(){  // 获得焦点 
    $(".error-prompt").css("display","none");
  }).blur(function(){     // 失去焦点
  });

  // 获取律师的信息
  // jumpUrl+'center/lawyer/info'
  var question_type =  JSON.parse(localStorage.getItem('question_type'));
  $.get(jumpUrl+'/lawyer/'+lawyer_id,function(data){

  },'json').error(function(data){

  }).success(function(data){
    var obj = data.data;
    var companyStore = JSON.parse(localStorage.getItem("companyStore"));//localStorage获取出来
    console.info(obj);
    var Price='';
    var str = '';
    if (question_type == "pay_text") {
        question_type1 ='图文咨询'
        Price = obj.text_reply_fee 
      }else if(question_type == "pay_phone") {
        question_type1 ='电话咨询'
        Price = obj.phone_reply_fee
      }else if(question_type == "adviser1") {
        question_type = "pay_company"
        question_type1 ='银卡'
        Price = companyStore[0].price
      }else if(question_type == "adviser2") {
        question_type = "pay_company"
        question_type1 ='金卡'
        Price = companyStore[1].price
      }else if(question_type == "adviser3") {
        question_type = "pay_company"
        question_type1 ='白金卡'
        Price = companyStore[2].price
      }else if(question_type == "adviser4") {
        question_type = "pay_company"
        question_type1 ='砖石卡'
        Price = companyStore[3].price
      }
    str+='<div class="fl"><img src="'+obj.avatar+'" width="80" height="80" style="border-radius:50%;margin: 10px 0px 0 0px;"></div>'
    str+='<div class="fl" style="margin: 30px 100px 0 20px;">'
      str+='<p class="colorE font18" style="line-height:30px;">'+ obj.realname +'</p>'
      str+='<p class="colorF font16">'+question_type1+'</p>'
    str+='</div>'
    str+='<div class="font14 colorD fr" style="margin: 60px 0px 0 0px;">支付金额：'

    str+='<span class="font22 colorC"> '+Price+' </span>元</div>'  
    $(".lv-type-info").append(str);

  });

     var product_id="";
    if(question_type == "adviser1") {
        product_id = "1"
      }else if(question_type == "adviser2") {
        product_id = "2"
      }else if(question_type == "adviser3") {
        product_id = "3"
      }else if(question_type == "adviser4") {
        product_id = "4"
      }
  //提交咨询
  $(document).on( "click", ".subAdvisory", function(e) {

      var content = $.trim($("#content").val());
      if(content.length < 1){
          $(".error-prompt").css("display","block");
          $(".textcon").text("内容不能为空！")
          return false;
      }else if(content.length < 10||content.length > 1000){
          $(".Error-prompt").css("display","block");
          $(".textcon").text("标题不能小于10个字或者大于1000个字！")
          return false;
      }else{
          var loading = layer.msg('加载中...', {icon: 16});
          $.post(jumpUrl+'/center/question/create/'+question_type,{"content":content,"lawyer_id":lawyer_id,"product_id":product_id},function(data){
                $(".error-prompt").css("display","none");
                if(islogin == "" || islogin == null){
                  var post_id_status = false;
                  localStorage.setItem("post_id_status", JSON.stringify(post_id_status));
                  sessionStorage.setItem("goback", location.href);
                   $(".loginPopup").click();
                }else{
                    layer.msg("发布成功");
                    var obj = data.data;
                    window.location.href=jumpUrl+"/center/question_order/"+obj+"/to_pay";
                    $(".filename ul li").remove();
                }
                layer.close(loading); 
                 $(".subAdvisory").removeAttr('disabled');
             }, "json").error(function(data) {
               var obj = $.parseJSON(data.responseText);
               layer.msg(obj.message);
             }).success(function(data){
              var obj = data.data;
             });
             
             return true;
      }
      stopDefault(e);
  });


})
